home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tsr25src.arc / FMARK.ASM < prev    next >
Assembly Source File  |  1987-06-02  |  9KB  |  260 lines

  1. ;==============================================================================
  2. ;FMARK.ASM - mark a position in memory,
  3. ;            above which TSRs will later be cleared by RELEASE.COM
  4. ;            this version leaves a minimal size MARK in memory,
  5. ;              storing the rest on disk
  6. ;            requires a single command line parameter naming
  7. ;              the file where the mark will be stored
  8. ;
  9. ; Syntax:  FMARK [d:][path]filename
  10. ;==============================================================================
  11. ; written for MASM (MicroSoft Assembler version 4)
  12. ; by Kim Kokkonen, TurboPower Software
  13. ; telephone: 408-438-8608, Compuserve 72457,2131
  14. ;==============================================================================
  15. ; VERSION 2.0  6/17/86
  16. ;   start at a version number compatible with other TSR utilities
  17. ; VERSION 2.1  7/18/86
  18. ;   keep consistent with RELEASE
  19. ; VERSION 2.2  3/4/87
  20. ;   add save area for BIOS data areas
  21. ;     40:A8 (8 bytes for EGA)
  22. ;     40:F0 (16 bytes for interapplications communications)
  23. ; VERSION 2.3  5/2/87
  24. ;   convert to MASM
  25. ; VERSION 2.4  5/17/87
  26. ;   for consistency with RELEASE
  27. ; VERSION 2.5  6/2/87
  28. ;   fix bug in memory allocated when command line is 15 bytes long
  29. ;   add version checking for consistency between FMARK and RELEASE
  30. ;==============================================================================
  31. ;
  32. Cseg      segment public para
  33.           assume  cs:Cseg, ds:Cseg, es:Cseg
  34.  
  35.           org     02CH
  36. envseg    label   word               ;access to environment segment
  37.  
  38.           org     80H
  39. cmdlen    label   byte               ;command line length
  40.           org     81H
  41. cmdlin    label   byte               ;first character of command line
  42.  
  43.           org     100H
  44.  
  45. fmark     proc    near
  46.  
  47. comentry:
  48.  
  49. ;parse command line for file name
  50.        mov     si,offset cmdlin ;point to command line
  51.        mov     di,offset filnm  ;point to filename storage string
  52.        cld
  53.  
  54. get1:  lodsb                    ;get first non-blank
  55.        cmp     al,32            ;skip space
  56.        je      get1
  57.        cmp     al,9             ;skip tab
  58.        je      get1
  59.        cmp     al,13            ;check for end of input
  60.        jne     get2             ;got a non-blank, now get the parameter
  61.        jmp     error            ;no parameter --> error
  62.  
  63. get2:  cmp     al,'a'
  64.        jl      sto1
  65.        cmp     al,'z'
  66.        jg      sto1
  67.        and     al,0DFH          ;uppercase
  68. sto1:  stosb                    ;store the non-blank character
  69.        lodsb                    ;get next character
  70.        cmp     al,32            ;terminate with blank, tab, or <cr>
  71.        je      gotit
  72.        cmp     al,9
  73.        je      gotit
  74.        cmp     al,13
  75.        je      gotit
  76.        jmp     short get2
  77.  
  78. ;create the specified file
  79. gotit: mov     al,0
  80.        stosb                    ;terminate ASCIIZ pathname
  81.        mov     dx,offset filnm
  82.        xor     cx,cx            ;normal attribute
  83.        mov     ah,3CH
  84.        int     21H              ;DOS CREAT
  85.        jae     store
  86.  
  87.        mov     dx,offset badfil ;bad file name
  88.        mov     ah,9
  89.        int     21H
  90.        jmp     error
  91.  
  92. ;store the interrupt vector table
  93. store: mov     bx,ax           ;keep file handle in bx
  94.        push    ds              ;save ds
  95.        mov     cx,400H         ;1024 bytes to store
  96.        xor     ax,ax
  97.        mov     ds,ax           ;segment 0
  98.        assume  ds:nothing
  99.        mov     dx,ax           ;offset 0
  100.        mov     ah,40H
  101.        int     21H             ;write block to file
  102.        pop     ds              ;get ds back
  103.        assume  ds:cseg
  104.        jae     egasav          ;ok, continue
  105.  
  106.        mov     dx,offset nowrit ;write error
  107.        mov     ah,9
  108.        int     21H
  109.        jmp     error
  110.  
  111. ;store the EGA save pointer
  112. egasav: push    ds             ;save ds
  113.        mov     cx,0008H        ;8 bytes to store
  114.        mov     ax,0040H
  115.        mov     ds,ax           ;BIOS data segment
  116.        assume  ds:nothing
  117.        mov     dx,00A8H        ;EGA save table pointer
  118.        mov     ah,40H
  119.        int     21H             ;write block to file
  120.        pop     ds              ;get ds back
  121.        assume  ds:cseg
  122.        jae     intcom          ;ok, continue
  123.  
  124.        mov     dx,offset nowrit ;write error
  125.        mov     ah,9
  126.        int     21H
  127.        jmp     error
  128.  
  129. ;store the interapplications communications area
  130. intcom: push    ds             ;save ds
  131.        mov     cx,0010H        ;16 bytes to store
  132.        mov     ax,0040H
  133.        mov     ds,ax           ;BIOS data segment
  134.        assume  ds:nothing
  135.        mov     dx,00F0H        ;interapplications communication area
  136.        mov     ah,40H
  137.        int     21H             ;write block to file
  138.        pop     ds              ;get ds back
  139.        assume  ds:cseg
  140.        jae     ems             ;ok, continue
  141.  
  142.        mov     dx,offset nowrit ;write error
  143.        mov     ah,9
  144.        int     21H
  145.        jmp     error
  146.  
  147. ;determine whether EMS is present
  148. ems:   push    bx              ;temporarily store the file handle
  149.        xor     bx,bx           ;zero the EMS handle count in case EMS not present
  150.        mov     dx,offset emsnm
  151.        mov     ax,3D00H
  152.        int     21H
  153.        jb      sthand          ;EMS driver not installed
  154.  
  155. ;EMS present, close the open "handle" first
  156.        mov     bx,ax           ;EMS handle into bx
  157.        mov     ah,3EH
  158.        int     21H             ;close handle
  159.  
  160. ;get the current EMS page map
  161.        mov     ah,4DH
  162.        mov     di,offset emsmap ;es=cs already
  163.        xor     bx,bx           ;required by some versions of EMM (bug workaround)
  164.        cld                     ;required by some versions of EMM
  165.        int     67H
  166.        or      ah,ah
  167.        jz      sthand          ;result ok
  168.        xor     bx,bx           ;error, return zero EMS handles
  169.  
  170. ;store the number of active handles
  171. sthand: mov     emscnt,bx      ;count of active handles
  172.  
  173. ;write the handle table to disk
  174.        shl     bx,1
  175.        shl     bx,1            ;4 bytes per handle
  176.        inc     bx
  177.        inc     bx              ;2 more bytes for the handle count
  178.        mov     cx,bx           ;number of bytes to write
  179.        pop     bx              ;get file handle back
  180.        mov     dx,offset emscnt ;what we're writing
  181.        mov     ah,40H
  182.        int     21H             ;write out the table
  183.        jae     closfl          ;ok,continue
  184.  
  185.        mov     dx,offset nowrit ;error while writing
  186.        mov     ah,9
  187.        int     21H
  188.        jmp     short error
  189.  
  190. ;close up the table file
  191. closfl: mov     ah,3EH
  192.        int     21H             ;close handle
  193.        jae     idstr           ;ok, continue
  194.  
  195.        mov     dx,offset badcls ;error while closing file
  196.        mov     ah,9
  197.        int     21H
  198.        jmp     short error
  199.  
  200. ;put a standard ID string into the PSP for RELEASE to check
  201. idstr: mov     si,offset id
  202.        mov     di,60H          ;unused area of the PSP
  203.        mov     cx,idlen        ;characters in ID string
  204.        cld
  205.        rep     movsb           ;copy string
  206.  
  207. ;deallocate environment block of this mark
  208. deall: mov     ax,envseg       ;environment segment
  209.        mov     es,ax           ;  into es
  210.        mov     ah,49H
  211.        int     21H             ;deallocate, no reason for an error to occur
  212.  
  213. ;print message and TSR
  214. gores: mov     dx,offset didit
  215.        mov     ah,9
  216.        int     21H             ;write success message including filename
  217.        mov     dx,offset crlf  ;newline
  218.        mov     ah,9
  219.        int     21H
  220.  
  221.        xor     dx,dx           ;get number of paragraphs to keep
  222.        mov     dl,cmdlen       ;length of command line
  223.        add     dx,0090H        ;rest of PSP plus paragraph margin
  224.        mov     cl,4
  225.        shr     dx,cl           ;convert to paragraphs
  226.        mov     ax,3100H
  227.        int     21H             ;terminate and stay resident
  228.  
  229. ;error output - show syntax line
  230. error: mov     dx,offset syntax
  231.        mov     ah,9
  232.        int     21H
  233.  
  234. ;exit with error
  235.        mov     ax,4C01H
  236.        int     21H
  237.  
  238. fmark  endp
  239.  
  240. emsnm  db      'EMMXXXX0',0    ;file name for testing EMS presence
  241. id     db      'FM2.5 TSR'     ;id string for RELEASE check
  242. idlen  equ     $-id
  243.  
  244. ;messages
  245. badfil db      13,10,'Could not open file for writing',36
  246. nowrit db      13,10,'Error while writing',36
  247. badcls db      13,10,'Error closing table file',36
  248. syntax db      13,10,'Syntax:  FMARK [d:][path]filename'
  249. crlf   db      13,10,36
  250. didit  db      13,10,'FMARK 2.5 - Marked current memory position in '
  251.  
  252. ;data storage area
  253. filnm  db      44H dup (36)    ;mark file name
  254. emscnt dw      0               ;holds number of active pages in map that follows
  255. emsmap db      0               ;holds EMS page map if installed
  256.                                ;(note may extend 1K bytes past end of file in memory)
  257.  
  258. Cseg    ends
  259.         end     ComEntry
  260.